<?php
	/**
		Processes inviting a user to a chat
		
		@author Joseph Fehrman
	*/
	$chatRoom = $_POST['chatRoom'];
	$username = $_POST['username'];
	include_once("../db/connection.php");
	
	//Query that pulls information from chatRoom
	$sqlUserExist = "Select username from users where username='$username'";
	$results = mysqli_query($conn, $sqlUserExist) OR die("Error on query: " . $sqlUserExist);
	$userExist = false;
	while ($row = mysqli_fetch_array($results, MYSQL_BOTH)){
		 if($username == $row['username']){
			echo "1";
			$userExist = true;
			if($userExist){
				$sqlAddToChat = "INSERT INTO chat_rel (username, chatID) values ('$username', '$chatRoom')";
				mysqli_query($conn, $sqlAddToChat) OR die("Error on query: " . $sqlAddToChat);
			}
		 }
	}
	echo "0";
	mysqli_close($conn);
?>